home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig10_01.jar / Ch10 / Fig10_01 / Piece1.cpp < prev    next >
C/C++ Source or Header  |  1997-10-28  |  849b  |  34 lines

  1. // Fig. 10.1: piece1.cpp
  2. // Member function definitions for class PieceWorker
  3. #include <iostream.h>
  4. #include "piece1.h"
  5.  
  6. // Constructor for class PieceWorker
  7. PieceWorker::PieceWorker( const char *first, const char *last, 
  8.                           double w, int q )
  9.    : Employee( first, last )  // call base-class constructor
  10. {
  11.    setWage( w );
  12.    setQuantity( q );
  13. }
  14.  
  15. // Set the wage
  16. void PieceWorker::setWage( double w ) 
  17.    { wagePerPiece = w > 0 ? w : 0; }
  18.  
  19. // Set the number of items output
  20. void PieceWorker::setQuantity( int q ) 
  21.    { quantity = q > 0 ? q : 0; }
  22.  
  23. // Determine the PieceWorker's earnings
  24. double PieceWorker::earnings() const
  25.    { return quantity * wagePerPiece; }
  26.  
  27. // Print the PieceWorker's name 
  28. void PieceWorker::print() const
  29. {
  30.    cout << "\n     Piece worker: ";
  31.    Employee::print();
  32. }
  33.  
  34.